require(["common", "jQuery", "coAjax", "queryString", "hash_routie"], function(jSouper, $, coAjax, QueryString, hash_routie) {
	var ip_requires = [];
	ip_requires.addXhr = function(xhr) {
		ip_requires.push(xhr);
	};
	ip_requires.abortXhr = function(xhr) {
		xhr.abort();
		ip_requires.removeXhr(xhr);
	};
	ip_requires.removeXhr = function(xhr) {
		ip_requires.splice(ip_requires.indexOf(xhr), 1);
	};
	var ipInfoCache = {};

	function _get_visitorInfo_data() {
		coAjax.get(appConfig.bus.visitor_statistical, {
			num: 20
		}, function(result) {
			App.set("$Cache.bus.visitor.total_number", result.result.total_number);
			var visitor_statistical = result.result.statistical;
			App.set("$Cache.bus.visitor.statistical", visitor_statistical);
			jSouper.forEach(visitor_statistical, function(item, index) {
				if (!item.ip_info_detail) {
					function _setInfo(ip_info) {
						item.ip_info_detail = ip_info.city;
						App.getModel().touchOff("$Cache.bus.visitor.statistical." + index);
					}
					if (ipInfoCache[item.ip]) {
						_setInfo(ipInfoCache[item.ip])
					} else {
						var xhr = coAjax.get(appConfig.bus.ip + item.ip, function(data) {
							var ip_info = data.result.data;
							//缓存数据
							ipInfoCache[item.ip] = ip_info;
							_setInfo(ip_info);
							ip_requires.removeXhr(xhr);
						});
						ip_requires.addXhr(xhr);
					}
				}
			});
		});
	}
	hash_routie.on("visitorinfo", function() {
		for (var i = 0, xhr; xhr = ip_requires[i];) {
			ip_requires.abortXhr(xhr);
		}
		_get_visitorInfo_data();
	});
});